from urllib.parse import urljoin


class DingAPI:
    API_DOMAIN = "https://api.dingtalk.com"
    OAPI_DOMAIN = "https://oapi.dingtalk.com"

    @classmethod
    def build_access_token_url(cls):
        access_token_path = "/v1.0/oauth2/accessToken"
        return urljoin(cls.API_DOMAIN, access_token_path)

    @classmethod
    def build_user_info_url(cls):
        path = "/topapi/v2/user/get"
        return urljoin(cls.OAPI_DOMAIN, path)

    @classmethod
    def build_create_calendar_url(cls, union_id: str):
        path = f"/v1.0/calendar/users/{union_id}/calendars/primary/events"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_query_calendar_url(cls, union_id: str):
        path = f"/v1.0/calendar/users/{union_id}/calendars/primary/events"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_delete_calendar_url(cls, union_id: str, calendar_id: str):
        path = f"/v1.0/calendar/users/{union_id}/calendars/primary/events/{calendar_id}?pushNotification=true"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_modify_calendar_url(cls, union_id: str, calendar_id: str):
        path = f"/v1.0/calendar/users/{union_id}/calendars/primary/events/{calendar_id}?pushNotification=true"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_create_todo_url(cls, union_id: str):
        path = f"/v1.0/todo/users/{union_id}/tasks?operatorId={union_id}"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_query_todo_url(cls, union_id: str):
        path = f"/v1.0/todo/users/{union_id}/org/tasks/query"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_delete_todo_url(cls, union_id: str, todo_id: str):
        path = f"/v1.0/todo/users/{union_id}/tasks/{todo_id}"
        return urljoin(cls.API_DOMAIN, path)

    @classmethod
    def build_update_todo_url(cls, union_id: str, todo_id: str):
        path = f"/v1.0/todo/users/{union_id}/tasks/{todo_id}"
        return urljoin(cls.API_DOMAIN, path)